var mongoose = require('../common/db');
// 用户数据集
var userSchema = new mongoose.Schema({
    username: String,
    password: String,
    userMail: String,
    userPhone: String,
    userAdmin: Boolean,
    userPower: Number,
    userStop: Boolean
});

// 用户的查找方法
userSchema.statics.findAll = function(callBack){
    this.find({}, callBack);
};

userSchema.statics.findById = function(user_id, callBack) {
    this.findOne({_id: user_id}, callBack);
};

// 使用用户名查找的方法
userSchema.statics.findByUsername = function(name, callBack){
    this.find({username:name}, callBack);
};

// 登录匹配是不是拥有相同的用户名、密码，并没有处于封停状态
userSchema.statics.findUserLogin = function(name, password, callBack){
    this.find({username:name, password:password, userStop:false}, callBack);
};

// 验证邮件、电话和用户名找到用户
userSchema.statics.findUserPassword = function(name, mail, phone, callBack){
    this.find({username:name, userMail:mail, userPhone:phone}, callBack);
};

var userModel = mongoose.model('user', userSchema);

module.exports = userModel;